查看mysql 数据库数据文件
1 | # mysql |
切换目录,配置文件上传git
- git ssh生成
1
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- ssh key
1
$ cat /root/.ssh/id_rsa.pub
docker mysql 镜像
1 | $ docker pull mysql |
docker 启动
1 | $ systemctl start docker |
docker mysql 启动
1 | $ docker run -p 3306:3306 --name dbmysql -e MYSQL_ROOT_PASSWORD=<my-secret-pw> -d mysql |
指定配置文件
1 | $ docker run -p 3306:3306 -v </my/custom>:/etc/mysql/conf.d --name \ |
指定数据文件
1 | $ docker run -p 3306:3306 -v /my/own/datadir:/var/lib/mysql --name dbmysql \ |
shell
1 | $ docker exec -it dbmysql bash |
shell - 问题
1 | Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' |
navicat 连接mysql v8
- 修改访问host
1
2
3
4
5$ docker run -d -p 3307:3306 --name dbmysql -e MYSQL_ROOT_PASSWORD=123456 mysql
# mysql
> alter user 'root'@'%' identified with mysql_native_password by '123456'; - 刷新
1
2# mysql
> flush privileges; - 查看
1
2# mysql
> select Host,User from mysql.user; - 连接 - ssh通道
mysql升级
mysqlserver数据内容导出
1
$ mysqldump --databases <dbname1> <dbname2> -uroot -p123456 > /var/lib/dbmysql/dump.sql
进入容器
1
2$ docker exec -it dbmysql bash
$ mysql -uroot -p导入sql dump文件
1
2
3docker exec -i dbmysql sh -c 'exec mysql -uroot -p"$MYSQL_ROOT_PASSWORD"' < /var/lib/dbmysql/dump.sql
# 此处会给出警告,
# mysqldump: [Warning] Using a password on the command line interface can be insecure查看数据库
此处各不相同,自行测试基于上述端口为3307,修改端口为3306
1
$ cd /var/lib/docker/container
修改对应的文件
1
2$ vi hostconfig.json
$ vi config.v2.json重新启动docker
1
2
3# 切记修改端口前,一定要stop docker,否则修改无效。
# systemctl stop docker
$ systemctl start docker
卸载之前的mysql
搜索已有mysql包
1
2
3
4
5
6$ rpm -qa|grep -i mysql
mysql-community-server-5.7.20-1.el7.x86_64
mysql-community-libs-5.7.20-1.el7.x86_64
mysql-community-libs-compat-5.7.20-1.el7.x86_64
mysql57-community-release-el7-7.noarch
mysql-community-client-5.7.20-1.el7.x86_64删除包
1
$ rpm -ev mysql-community-common-5.7.20-1.el7.x86_64
搜索配置
1
2
3
4
5[root@VM_0_5_centos dbmysql]# find / -name mysql
/usr/share/mysql
/etc/selinux/targeted/active/modules/100/mysql
/etc/selinux/targeted/tmp/modules/100/mysql
/etc/mysql删除配置文件
1
rm -rf /etc/my.cnf
参考
赏
使用支付宝打赏
使用微信打赏
若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏